﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【超级用户】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto超级用户
    /// </summary>
    public abstract class AutoSuperUserMapping : BaseMapping<SuperUser, SuperUserModel, SuperUserFilterModel>
    {
        public AutoSuperUserMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override SuperUserModel Entity2Model(SuperUser entity)
        {
            SuperUserModel model = new SuperUserModel();

            model.SuperUserID = entity.SuperUserID;
            model.LoginName = entity.LoginName;
            model.LoginPassword = entity.LoginPassword;
            model.Name = entity.Name;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override SuperUser Model2Entity(SuperUserModel model)
        {
            SuperUser entity = new SuperUser();

            entity.SuperUserID = model.SuperUserID;
            entity.LoginName = model.LoginName;
            entity.LoginPassword = model.LoginPassword;
            entity.Name = model.Name;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<SuperUser> FilterModel2Where(SuperUserFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._SuperUserID.HasValue)
            {
                where = where.And(x => x.SuperUserID == filterModel._SuperUserID.Value);
            }
            if (filterModel._SuperUserIDs.IsNotEmpty() && filterModel._SuperUserIDs.Count > 0)
            {
                where = where.And(x => filterModel._SuperUserIDs.Contains(x.SuperUserID));
            }
            if (filterModel._NotSuperUserIDs.IsNotEmpty() && filterModel._NotSuperUserIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotSuperUserIDs.Contains(x.SuperUserID));
            }

            //登录名
            if (!string.IsNullOrEmpty(filterModel._LoginName))
            {
                where = where.And(x => x.LoginName.Contains(filterModel._LoginName));
            }
            if (!string.IsNullOrEmpty(filterModel._LoginNameEqual))
            {
                where = where.And(x => x.LoginName == filterModel._LoginNameEqual);
            }

            //姓名
            if (!string.IsNullOrEmpty(filterModel._Name))
            {
                where = where.And(x => x.Name.Contains(filterModel._Name));
            }
            if (!string.IsNullOrEmpty(filterModel._NameEqual))
            {
                where = where.And(x => x.Name == filterModel._NameEqual);
            }

            return where;
        }
        #endregion
    }
}

